<?php
/**
 * ajax server side review delete
 */
if( !isset($_POST['rid']) || !is_numeric($_POST['rid']) ) {
	echo "删除失败！";
	edp_exit();
}

$rid = intval($_POST['rid']);
$reviewDao = GetReviewDAO();
//check whether the review belongs to current user
$reviewInfo = $reviewDao->GetReviewInfo( $rid );

if( !$reviewInfo || $reviewInfo['user_id'] != GetLoginUserID() ){
	echo "没有权限删除此评论";
}
else{
	if( $reviewDao->DeleteReview( GetLoginUserID(), $rid ) ) {
		echo "删除成功";
		//also insert task to message queue
		$taskMgr = GetTaskManager();
		$taskMgr->AddShopScoreTask( $reviewInfo['shop_id'] );
		if( !empty( $reviewInfo['product_id_list'] ) ){
			$idlist = explode( ",", $reviewInfo['product_id_list'] );
			foreach( $idlist as $id ){
        			$taskMgr->AddProductScoreTask( $id );
			}
		}
	}
	else
		echo "删除失败！请稍后再试。。。";
}
edp_exit();
?>
